//
// Created by crg on 2018/8/17.
//

#include "chapter7.h"
#include <iostream>
#include <string>
#include <sstream>

using namespace std;
namespace Chapter7{
    void SpreadsheetCell::setValue(double inValue) {
        mValue = inValue;
        mString = doubleToString(inValue);
    }

    double SpreadsheetCell::getValue() const {
        return mValue;
    }

    void SpreadsheetCell::setString(const std::string &inString) {
        mString = inString;
        mValue = stringToDouble(inString);
    }

    const std::string& SpreadsheetCell::getString() const {
        return mString;
    }

    double SpreadsheetCell::stringToDouble(const std::string &inString) const {
        double temp;
        istringstream istr(inString);
        istr >> temp;
        if (istr.fail()||istr.eof()){
            return 0;
        }
        return temp;
    }

    string SpreadsheetCell::doubleToString(double inValue) const {
        ostringstream ostr;
        ostr << inValue;
        return ostr.str();
    }





}